package com.ruoyi.ai.config.gateway;

import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.constant.GatewayConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 网关配置，暂时废弃，走nginx
 */
@Deprecated
@ConditionalOnProperty(name = "ruoyi.gatewayEnabled", havingValue = "true")
@RestController
@RequestMapping(GatewayConstants.FILE_ROUTE_PREFIX)
public class FileRouteController {
    @Autowired
    private RuoYiConfig ruoYiConfig;

    @Autowired
    private RoutingDelegate routingDelegate;

    @RequestMapping(value = "/**", method = {RequestMethod.GET})
    public ResponseEntity catchAll(HttpServletRequest request, HttpServletResponse response) {
        return routingDelegate.redirect(request, ruoYiConfig.getFileGatewayUrl(), GatewayConstants.FILE_ROUTE_PREFIX, true);
    }
}
